package com.youdoneed.community.forum.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.youdoneed.community.common.vo.PageData;
import com.youdoneed.community.common.vo.ResultMessage;
import com.youdoneed.community.forum.entity.Forummessagelabel;
import com.youdoneed.community.forum.service.ForummessagelabelService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 猿圈论坛标签模块控制器
 *
 * @author lid
 * @date 2017.6.7
 */
@SuppressWarnings("unchecked")
@RestController
@RequestMapping(value = "/forumMessageLabel", method = {RequestMethod.GET, RequestMethod.POST})
@Api(value = "论坛信息标签模块控制器", description = "论坛信息标签模块相关操作")
public class ForummessagelabelController {

    /**
     * 猿圈帖子标签删除状态
     */
    public static int deleteStatus = 1;
    public static int recoveryStatus = 0;

    private static final Logger logger = LoggerFactory.getLogger(ForummessagelabelController.class);
    @Autowired
    ForummessagelabelService forummessagelabelService;

    /**
     * 后台删除信息标签
     *
     * @param labelId
     * @author lixs
     * @Date 2017.7.13
     */
    @RequestMapping(value = "/deleteForumMessageLabel", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台删除信息标签", value = "后台删除信息标签")
    public ResultMessage<Forummessagelabel> deleteForumReportLableById(String labelId) {
        logger.info("根据id" + labelId + "删除记录");
        Forummessagelabel label = forummessagelabelService.selectForumMessageLabelById(labelId);
        label.setLabelStatus(deleteStatus);
        forummessagelabelService.updateForumMessageLabel(label);
        return ResultMessage.newSuccess("后台删除信息标签成功");

    }

    /**
     * 后台恢复信息标签
     *
     * @param labelId
     * @author lixs
     * @Date 2017.7.13
     */
    @RequestMapping(value = "/recoveryForumMessageLabel", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台恢复信息标签", value = "后台恢复信息标签")
    public ResultMessage<Forummessagelabel> recoveryForumReportLableById(String labelId) {
        logger.info("根据id" + labelId + "恢复记录");
        Forummessagelabel label = forummessagelabelService.selectForumMessageLabelById(labelId);
        label.setLabelStatus(recoveryStatus);
        forummessagelabelService.updateForumMessageLabel(label);
        return ResultMessage.newSuccess("后台恢复信息标签成功");

    }

    /**
     * 后台保存猿圈帖子标签（添加）
     *
     * @param forummessagelabel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/saveForumMessageLabel", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台保存猿圈帖子标签", value = "后台保存猿圈帖子标签")
    public ResultMessage<?> saveForumMessageLabel(Forummessagelabel forummessagelabel) {
        logger.info("保存记录");
        if (null == forummessagelabel) {
            logger.info("forummessagelabel对象为空");
            return ResultMessage.newFailure("forummessagelabel对象为空");
        }

        forummessagelabelService.saveForumMessageLabel(forummessagelabel);

        return ResultMessage.newSuccess("后台保存猿圈帖子标签成功");

    }

    /**
     * 后台查询信息标签
     *
     * @param id
     * @author lixs
     * @Date 2017.7.13
     */
    @RequestMapping(value = "/selectForumMessageLabel", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台查询信息标签", value = "后台查询信息标签")
    public ResultMessage<Forummessagelabel> selectForumReportLableById(String id) {
        logger.info("查询记录");
        Forummessagelabel label = forummessagelabelService.selectForumMessageLabelById(id);
        if (label == null) {
            return ResultMessage.newFailure("后台查询信息标签失败");
        }
        return ResultMessage.newSuccess("后台查询信息标签成功！").setData(label);

    }

    /**
     * 后台修改信息标签
     *
     * @param forummessagelabel
     * @author lixs
     * @Date 2017.7.13
     */
    @RequestMapping(value = "/updateForumMessageLabel", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台修改信息标签", value = "后台修改信息标签")
    public ResultMessage<Integer> updateForumReportLableById(@RequestBody Forummessagelabel forummessagelabel) {
        logger.info("修改记录");
        forummessagelabelService.updateForumMessageLabel(forummessagelabel);
        return ResultMessage.newSuccess("后台修改论坛标签成功！");
    }

    /**
     * 获取所有的启用标签
     *
     * @return ResultMessage
     * @author lid
     * @date 2017.6.7
     */
    @RequestMapping(value = "/queryAllForumMessageLabel", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "获取所有论坛标签", value = "获取所有论坛标签")
    public ResultMessage<List<Forummessagelabel>> queryAllForumMessageLabel() {
        logger.info("获取所有论坛标签");
        List<Forummessagelabel> listForummessagelabel = forummessagelabelService.getAllForummessagelabels();
        if (null != listForummessagelabel) {
            return ResultMessage.newSuccess("获取所有论坛标签成功").setData(listForummessagelabel);
        }
        return ResultMessage.newFailure("获取所有论坛标签失败");
    }

    /**
     * 多条件查询论坛标签
     *
     * @param labelDescribe
     * @return ResultMessage
     * @author lixs
     * @date 2017.6.9
     */
    @RequestMapping(value = "/getSearcherForummessagelabel", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "模糊查询论坛标签", value = "模糊查询信息标签")
    public ResultMessage<PageData> getSearcherForummessagelabel(String labelDescribe, Integer labelStatus, String createDateS, String createDateE, Integer limit, Integer offset) {
        logger.info("模糊查询论坛标签");
        List<Forummessagelabel> listForummessagelabel = forummessagelabelService.getSearcherForummessagelabel(labelDescribe, labelStatus, createDateS, createDateE, offset, limit);
        if (null == listForummessagelabel) {
            return ResultMessage.newFailure("模糊查询论坛标签失败");
        }
        List<Forummessagelabel> listmessagelabel = forummessagelabelService.getSearcherForummessagelabelForTotal(labelDescribe, labelStatus, createDateS, createDateE);
//		Map<String,Object> resultMap =new HashMap<String,Object>();
//		resultMap.put("rows", listForummessagelabel);
//		resultMap.put("total", listmessagelabel.size());
//		logger.info("total"+listmessagelabel.size());
        PageData page = new PageData();
        page.setRows(listForummessagelabel);
        page.setTotal(listmessagelabel.size());
        return ResultMessage.newSuccess("模糊查询论坛标签成功").setData(page);

    }
}
